package com.edu.chapter07;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class TweensActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tweens);

        ImageView a = findViewById(R.id.iv_a);

//        @SuppressLint("ResourceType") Animation animation = AnimationUtils.loadAnimation(this,R.drawable.anim_translate);
//        animation.setRepeatCount(Animation.INFINITE);
//        imageView.startAnimation(animation);
        TranslateAnimation translateAnimationA = new TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0f,
                Animation.RELATIVE_TO_PARENT, 0.5f,
                Animation.RELATIVE_TO_PARENT, 0f,
                Animation.RELATIVE_TO_PARENT, 0.5f);
        translateAnimationA.setDuration(3000);
        translateAnimationA.setRepeatCount(Animation.INFINITE);
        a.startAnimation(translateAnimationA);

        ImageView b = findViewById(R.id.iv_b);
//        @SuppressLint("ResourceType") Animation animation = AnimationUtils.loadAnimation(this, R.drawable.anim_scale);
//        animation.setRepeatCount(Animation.INFINITE);
//        b.startAnimation(animation);
        ScaleAnimation translateAnimationB = new ScaleAnimation(
                1f, 0.2f,
                1f, 0.2f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        translateAnimationB.setDuration(3000);
        translateAnimationB.setRepeatCount(Animation.INFINITE);
        b.startAnimation(translateAnimationB);

        ImageView c = findViewById(R.id.iv_c);
        RotateAnimation animationC = new RotateAnimation(
                0f, 360f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f
        );
        animationC.setRepeatCount(Animation.INFINITE);
        animationC.setDuration(2000);
        c.startAnimation(animationC);
//        Animation animation = AnimationUtils.loadAnimation(this, R.drawable.anim_rotate);
//        c.startAnimation(animation);

//        Animation animation = AnimationUtils.loadAnimation(this, R.drawable.anim_alpha);
        AlphaAnimation animationD = new AlphaAnimation(0.0f, 1.0f);
        animationD.setDuration(500);
        animationD.setRepeatCount(Animation.INFINITE);
        animationD.setRepeatMode(Animation.REVERSE);
        findViewById(R.id.iv_d).startAnimation(animationD);

//        Animation animation = AnimationUtils.loadAnimation(this, R.drawable.anim_set);
//        animation.setRepeatCount(Animation.INFINITE);
//        animation.setRepeatMode(Animation.REVERSE);
//        findViewById(R.id.iv_e).startAnimation(animation);

        AnimationSet animationSet = new AnimationSet(true);
        animationSet.addAnimation(translateAnimationA);
        animationSet.addAnimation(translateAnimationB);

        RotateAnimation rotateAnimation = new RotateAnimation(
                0f, 360f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f
        );
        rotateAnimation.setRepeatCount(Animation.INFINITE);
        rotateAnimation.setDuration(2000);
        animationSet.addAnimation(rotateAnimation);
        animationSet.addAnimation(animationD);

        findViewById(R.id.iv_e).startAnimation(animationSet);

    }
}